//
//  AllTypesCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/11/30.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class AllTypesCell: UICollectionViewCell {
    
    // MARK: - life cycle
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initBaseLayout()
        layoutPageSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.backgroundColor = UIColor.white
        self.addSubview(iconImageView)
        self.addSubview(contentLabel)
    }
    
    func layoutPageSubviews() {
        iconImageView.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(12)
            make.centerX.equalTo(self)
            make.width.height.equalTo(40)
        }
        
        contentLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(self).offset(-11)
            make.centerX.equalTo(self)
            make.width.equalTo(50)
            make.height.equalTo(17)
        }
    }
    
    func configUI(imageUrl: String, categoryName: String) {
        iconImageView.sd_setImage(with: URL(string: imageUrl), placeholderImage: UIImage(named: "def_40x40"))
        contentLabel.text = categoryName
    }
    
    // MARK: - setters and getters
    var _iconImageView: UIImageView!
    var iconImageView: UIImageView {
        if _iconImageView == nil {
            _iconImageView = UIImageView()
        }
        return _iconImageView
    }
    
    var _contentLabel: UILabel!
    var contentLabel: UILabel {
        if _contentLabel == nil {
            _contentLabel = UILabel()
            _contentLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
            _contentLabel.textColor = UIColor(hexString: "#252525")
            _contentLabel.textAlignment = .center
        }
        return _contentLabel
    }
}
